﻿using Microsoft.AspNetCore.Mvc;
using Shop.Core.Share;
using Shop.IServices.hea;
using Shop.Model.Dto.Hea;
using Shop.Model.View.Hea;

namespace Shop.WebApi.Controllers
{
    /// <summary>
    /// 健康自检
    /// </summary>
    [ApiController]
    [Route("Api/[controller]")]
    public class HealthController: ShopControllerBase
    {
        private readonly IHealthAppService _healthAppService;
        private readonly IUserContext _userContext;
    
        public HealthController(IHealthAppService healthAppService,
            IUserContext userContext)
        {
            _healthAppService = healthAppService;
            _userContext = userContext;
        }
    
        /// <summary>
        /// 开始答题
        /// </summary>
        /// <param name="classify">类型</param>
        /// <returns></returns>
        [HttpGet("Exam")]
        public async Task<AppResult<StartAnswerVo>> StartAnswer([FromQuery]int classify = 1)
        {
            return await _healthAppService.StartAnswer(_userContext.Id, classify);
        }
    
        /// <summary>
        /// 提交答题并获取报告
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        [HttpPost("Submit")]
        public async Task<AppResult<HealthReportVo>> UserAnswer(UserAnswerParaDto input)
        {
            try
            {
                var data = await _healthAppService.UserAnswer(input);
                return await _healthAppService.GetHealthUserExam(data);
            }
            catch (Exception ex)
            {
                return Problem(ex.ToString());
            }
            
        }
    
        /// <summary>
        /// 获取报告
        /// </summary>
        /// <param name="id">检查记录ID</param>
        /// <returns></returns>
        [HttpGet("Report")]
        public async Task<AppResult<HealthReportVo>> GetHealthUserExam([FromQuery]long id)
        {
            try
            {
                return await _healthAppService.GetHealthUserExam(id);
            }
            catch (Exception ex)
            {
                return Problem(ex.ToString());
            }
        }
    }
}